"""
Case Type   : 资源池化
Case Name   : 扩容工具不指定XMLgs_expansion -U omm -G dbgrp -h 192.168.0.1 指定参数错误
Create At   : 2024.10
Owner       : chen
Description :
    1.指定用户组不存在
    2.指定主机有误
Expect      :
    1.执行失败，合理报错
    2.执行失败，合理报错
"""

import os
import unittest
from testcase.utils.Logger import Logger
from yat.test import Node
from yat.test import macro

class SharedStorage(unittest.TestCase):
    def setUp(self):
        self.log = Logger()
        self.log.info(f'-----{os.path.basename(__file__)} start-----')
        self.pri_node = Node('PrimaryDbUser')
        self.pri_root_node = Node('PrimaryRoot')
        self.db_host = Node('Standby2DbUser').db_host
        self.db_name = self.pri_node.ssh_user

    def test_shared_storage(self):
        text = '-----step1: 指定用户组不存在 expect: 合理报错-----'
        self.log.info(text)
        cmd = f'''source {macro.DB_ENV_PATH}; 
            gs_expansion -U case004 -G case004 -h {self.db_host}'''
        self.log.info(cmd)
        res = self.pri_root_node.sh(cmd).result()
        self.log.info(res)
        self.assertIn('User case004 does not exist', res)

        text = '-----step2: 指定主机有误 expect: 合理报错-----'
        self.log.info(text)
        gs_expansion_cmd = f'''gs_expansion \
            -U {self.db_name} -G {self.db_name} -h 10.10.10.10'''
        execute_cmd = f'''source {macro.DB_ENV_PATH};
            expect <<EOF
            set timeout 600
            spawn {gs_expansion_cmd}
            expect "*assword*:"
            send "{self.pri_root_node.ssh_password}\\n"
            expect eof\n''' + '''EOF'''
        self.log.info(execute_cmd)
        res = self.pri_root_node.sh(execute_cmd).result()
        self.log.info(res)
        self.assertIn('The IP address 10.10.10.10 is incorrect', res)

    def tearDown(self):
        self.log.info(f'-----{os.path.basename(__file__)} end-----')